package test.patches;

import basemod.ReflectionHacks;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.evacipated.cardcrawl.modthespire.lib.*;
import com.evacipated.cardcrawl.modthespire.patcher.PatchingException;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.helpers.FontHelper;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.rooms.MonsterRoom;
import com.megacrit.cardcrawl.saveAndContinue.SaveFile;
import javassist.CannotCompileException;
import javassist.CtBehavior;
import javassist.expr.ExprEditor;
import javassist.expr.MethodCall;
import test.character.Captain;
import test.monitors.SeaMonitor;

import java.util.ArrayList;

public class RoomCreaturesMoveUpPatch {

    @SpirePatch(
            clz = AbstractDungeon.class,
            method = "nextRoomTransition",
            paramtypez = {
                    SaveFile.class
            }
    )
    public static class NextRoomTransitionPatch {
        @SpireInsertPatch(
                locator = Locator.class
        )
        public static void insert(AbstractDungeon __instance, SaveFile saveFile) {
            if(AbstractDungeon.currMapNode.room instanceof MonsterRoom){
                AbstractDungeon.player.movePosition(AbstractDungeon.player.drawX,AbstractDungeon.player.drawY+200.0f*Settings.scale);
            }
            for(AbstractMonster m : AbstractDungeon.getMonsters().monsters){
                m.drawY+=200.0f*Settings.scale;
            }
        }

        private static class Locator extends SpireInsertLocator {
            public int[] Locate(CtBehavior ctMethodToPatch) throws CannotCompileException, PatchingException {
                Matcher finalMatcher = new Matcher.MethodCallMatcher(AbstractPlayer.class, "preBattlePrep");

                int[] lines = LineFinder.findInOrder(ctMethodToPatch, new ArrayList<Matcher>(), finalMatcher);
                return new int[]{lines[0]+2};
            }
        }
    }


}
